package com.uzhie.web.controller.websocket;

import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * Created by TangFei on 2018/8/9.
 */
public class WebsocketMethodInvoke<T> {

    public volatile ConcurrentMap<T, WebsocketClassMethod> methodMap = new ConcurrentHashMap();

    public WebsocketMethodInvoke() {
    }

    public void put(T requestMethod, WebsocketClassMethod classMethod) {
        methodMap.put(requestMethod, classMethod);
    }

    public Object invoke(T msgID, Object... params) throws InvocationTargetException, IllegalAccessException {
        WebsocketClassMethod classMethod = methodMap.get(msgID);
        Object invoke = classMethod.getMethod().invoke(classMethod.getClazzIns(), params);
        return invoke;
    }

}
